#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\res\plugin.ico
#AutoIt3Wrapper_Outfile=out\putty2.exe
#AutoIt3Wrapper_Res_Comment=putty
#AutoIt3Wrapper_Res_Fileversion=0.1.0.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.16.1
 Author:         myName

 Script Function:
	Template AutoIt script.

#ce ----------------------------------------------------------------------------
#include <MsgBoxConstants.au3>

$aLogPath = @AppDataDir & "\PuTTY\putty2.log"
FileWriteLine($aLogPath ,"[" & $CmdLineRaw & @CRLF)
FileWriteLine($aLogPath ,"[WorkDir: " & @WorkingDir & @CRLF)


;$sFilePath = @ScriptDir & "\" & "putty2.ini"
$sFilePath = @AppDataDir & "\PuTTY\putty2.ini"
$portDef = ""

; Read the INI section names. This will return a 1 dimensional array.
Local $nArray = IniReadSectionNames($sFilePath)

; Check if an error occurred.
If Not @error Then
	; Enumerate through the array displaying the section names.
	;MsgBox($MB_SYSTEMMODAL, "", "Count down!" & @CRLF & $nArray[0])

	For $a = 1 To $nArray[0] Step 1
		$vSectionName = $nArray[$a]
		;MsgBox($MB_SYSTEMMODAL, "", "Section: " & $vSectionName)
		Local $aArray = IniReadSection($sFilePath, $vSectionName)
		;MsgBox($MB_SYSTEMMODAL, "", "Key: " & $sFilePath)
		; Check if an error occurred.
		If Not @error Then
			; Enumerate through the array displaying the keys and their respective values.
			For $i = 1 To $aArray[0][0] Step 1
				$portDef = $portDef & " " & $aArray[$i][0] & " " & $aArray[$i][1];
				;MsgBox($MB_SYSTEMMODAL, "", "Key: " & $aArray[$i][0] & @CRLF & "Value: " & $aArray[$i][1])
				;MsgBox($MB_SYSTEMMODAL, "", $portDef)
			Next
		EndIf
		;MsgBox($MB_SYSTEMMODAL, "", "Section: " & $vSectionName & "End")
	Next
EndIf
FileWriteLine($aLogPath, "[" & $portDef & @CRLF)
;MsgBox($MB_SYSTEMMODAL, "", $portDef)

#cs
$portDefineFile = @AppDataDir & "\PuTTY\putty2.ini"
$portDef = "127.0.0.1:8080:127.0.0.1:10000"
$sFileRead  = FileReadLine ( $portDefineFile, 2 )
If $sFileRead = 1 or $sFileRead = -1 or $sFileRead = "" Then
	;$portDef =
Else
	$portDef = $sFileRead
EndIf
#ce
;ConsoleWrite($CmdLineRaw & @CRLF)

; 初始命令
$mFilePath = @AppDataDir & "\PuTTY\command.txt"
$mFileExits = FileExists($mFilePath)
; Display a message of whether the file exists or not.
$runCommand = ""
If $mFileExits Then
	$runCommand = "putty.exe " & $CmdLineRaw & " -m " & $mFilePath & " " & $portDef
Else
	$runCommand = "putty.exe " & $CmdLineRaw & " " & $portDef
EndIf
ConsoleWrite($runCommand & @CRLF)
FileWriteLine($aLogPath, "[" & $runCommand & @CRLF)

Run($runCommand)






